<!--Generate by Kevin's CodeBuilder 2021-09-12 16:09:23 -->
<!--请注意！这里是页面片段，定义的标签ID，js变量不要与index.html列表页面重复-->
<!--如果是较复杂的页面，可以修改window的数据类型(dataType: iframe),然后将form.html改为完整的页面,实现iframe隔离，需要修改curdObj的访问方式为parent.curdObj-->
<div id="inof_form_container" class="form_container" style="padding-top: 25px">
    <!--利用隐藏的id标签区分是新增/编辑-->
    <input type="hidden" id="id" name="id" th:value="*{id}"/>
    <table class="k_form_table">
				<tr>
					<td class="label label20">旧密码</td>
					<td><input id="oldPwd" placeholder="留空即不修改密码" name="oldPwd" class="form_input form_input50 k_box_size" type="password"/></td>
				</tr>
				<tr>
					<td class="label label20">新密码</td>
					<td><input id="userPwd" placeholder="留空即不修改密码" name="userPwd" class="form_input form_input50 k_box_size" type="password"/></td>
				</tr>
				<tr >
					<td class="label label30">确认密码</td>
					<td><input id="newpwd" name="newpwd" class="form_input form_input50" type="password"/></td>
				</tr>
				<tr>
					<td class="label label20">电话</td>
					<td><input id="userPhone" name="userPhone" class="form_input form_input50 k_box_size" type="text"/></td>
				</tr>
				<tr>
					<td class="label label20">邮箱</td>
					<td><input id="userEmail" name="userEmail" class="form_input form_input50 k_box_size" type="text"/></td>
				</tr>
				<tr>
					<td class="button_td" colspan="2" style="padding-top:15px">
						<button id="button_submit" class="k_common_button"><i class="fa fa-floppy"></i> <span>[(${Lang.common_save})]</span></button>
						<button id="button_goback" class="k_common_button"><i class="fa fa-reply-all"></i><span>[(${Lang.common_closed})]</span></button>
					</td>
				</tr>
    </table>
	<p id="_retmsg" style="line-height: 1.5em;text-align: center;color: red;"></p>
</div>
<script type="application/javascript" th:src="@{/static/lib/vue.min.js}"></script>
<script type="application/javascript" th:inline="javascript">

    $B.DomUtils.onDomLoaded(function () {
		var vueForm,
				entityJson = [(${entityJson})],
				$form = document.getElementById("inof_form_container");

        /***定义验证字段 ，配置监听回调等***/
        var formOpt = {
            verifyOnChange: true,
            verify: {
				oldPwd:'require',
				userPwd:['password','require'],
				userPhone:'phone',
				userEmail:'email'
            }
        };

        /**自定义控件配置,请参考Bui表单控件***/
        var diyCtls = {} ;
        vueForm = $B.vueForm( $form,entityJson,diyCtls,formOpt);
        $form = vueForm.$form;
        /**绑定事件**/
        $B.DomUtils.click(document.getElementById("button_goback"), function () {
			vueForm.toDestroy();
			window._$infoWin.close();
        });
        var $msg = $B.DomUtils.findbyId($form,"_retmsg");
        var $pwd =  $B.DomUtils.findbyId($form,"newpwd");
		var $pwdOld =  $B.DomUtils.findbyId($form,"oldPwd");
		var onFocusFN = function(e){
			$B.DomUtils.removeClass(this,"k_input_value_err");
			$msg.innerText = "";
		};
		$B.DomUtils.focus($pwd,onFocusFN);
		$B.DomUtils.focus($pwdOld,onFocusFN);
        $B.DomUtils.click(document.getElementById("button_submit"), function () {
            if(vueForm.toVerify()){
                var prs = vueForm.toJSON();
                var msg = [];
                if(prs.userPwd !== "" && prs.userPwd !== prs.newpwd){
					msg.push("新密码不一致！");
					$B.DomUtils.addClass($pwd,"k_input_value_err");
				}
				if(prs.userPwd !== "" && prs.oldPwd === ""){
					msg.push("旧密码不能为空！");
					$B.DomUtils.addClass($pwdOld,"k_input_value_err");
				}
				if(msg.length === 0){
					let url = $B.getHttpHost()+"public/updateinfo";
					prs.oldPwd = $B.AESEncrypt(prs.oldPwd ,AESKey);
					prs.newPwd = $B.AESEncrypt(prs.newPwd ,AESKey);
					$B.request({
						data:prs,
						url: url,
						ok:function () {
							$B.success("更新成功！",1.2);
							vueForm.toDestroy();
							window._$infoWin.close();
						}
					},this);
				}else{
					$msg.innerText = msg.join("  ");
				}
                console.log(prs);
            }else{
                $B.error("[(${Lang.common_verify_err})]",1.5);
            }
        });
    });
</script>
